﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Project.Domain.AggregateModels;
using System;
using System.Collections.Generic;
using System.Text;
using ProjectEntity = Project.Domain.AggregateModels.Project;

namespace Project.Infrastructure.Models.Mapping
{
    public class ProjectMap
        : IEntityTypeConfiguration<ProjectEntity>
    {
        public void Configure(EntityTypeBuilder<ProjectEntity> builder)
        {
            //Table.
            builder.ToTable("Project");
            //Key.
            builder.HasKey("Id");
            //Properties.
            builder.Property(t => t.Id)
                .HasColumnName("Id")
                .IsRequired();
            builder.Property(t => t.Name)
               .HasColumnName("Name")
               .HasMaxLength(20)
               .IsUnicode(true)
               .IsRequired();
            builder.Property(t => t.Avatar)
               .HasColumnName("Avatar")
               .HasMaxLength(255)
               .HasDefaultValue("https://gitee.com/uploads/18/1183118_gainorloss_259.png?1483611120")
               .IsRequired();
            builder.Property(t => t.ProvinceId)
               .HasColumnName("ProvinceId")
               .IsRequired();
            builder.Property(t => t.ProvinceName)
               .HasColumnName("ProvinceName")
               .HasMaxLength(20)
               .IsRequired(false);
            builder.Property(t => t.CityId)
               .HasColumnName("CityId")
               .IsRequired();
            builder.Property(t => t.CityName)
               .HasColumnName("CityName")
               .HasMaxLength(20)
               .IsRequired(false);
            builder.Property(t => t.AreaId)
               .HasColumnName("AreaId")
               .IsRequired();
            builder.Property(t => t.AreaName)
               .HasColumnName("AreaName")
               .HasMaxLength(20)
               .IsRequired(false);
            builder.Property(t => t.RegisteTime)
               .HasColumnName("RegisteTime")
               .IsRequired();
            builder.Property(t => t.CreateTime)
               .HasColumnName("CreateTime")
               .HasDefaultValue(DateTime.Now)
               .IsRequired();
            builder.Property(t => t.UserId)
              .HasColumnName("UserId")
              .IsRequired();
            builder.Property(t => t.Introduction)
              .HasColumnName("Introduction")
              .HasMaxLength(255)
              .IsRequired();
            //Relations
            builder.HasMany(t => t.Properties);
            builder.HasMany(t => t.Viewers);
            builder.HasMany(t => t.Contributors);
            builder.HasOne(t => t.ProjectVisibleRule);
        }
    }
}
